package com.srit.system.bean;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 数据库表
 * 
 * @author guan
 * 
 * 
 */
public class DbTable implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	static Logger log = LoggerFactory.getLogger(DbTable.class);
	private Integer id;// 主键
	private String tableName;
	private String schema;
	private String remarks;// 备注
	private List<DbColumn> dbColumns = new ArrayList<DbColumn>();

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getSchema() {
		return schema;
	}

	public void setSchema(String schema) {
		this.schema = schema;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public List<DbColumn> getDbColumns() {
		return dbColumns;
	}

	public void setDbColumns(List<DbColumn> dbColumns) {
		this.dbColumns = dbColumns;
	}

	public static void main(String[] args) throws FileNotFoundException,
			IOException, ClassNotFoundException {
		DbTable tmp = new DbTable();
		DbColumn c1 = new DbColumn();
		c1.setColumnName("c1");
		DbColumn c2 = new DbColumn();
		c2.setColumnName("c2");
		DbColumn c3 = new DbColumn();
		c3.setColumnName("c3");
		List<DbColumn> columns = new ArrayList<DbColumn>();
		columns.add(c1);
		columns.add(c2);
		columns.add(c3);
		tmp.setDbColumns(columns);
		tmp.setTableName("aaaaa");
		System.out.println(tmp);
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
				DbTable.class.getName())); // 准备写入的文件
		out.writeObject(tmp);
		out.flush();
		out.close(); // 执行到这里你可以看见worm.out这个文件，
		// 以下的代码读出你刚刚写入Object
		ObjectInputStream in = new ObjectInputStream(new FileInputStream(
				DbTable.class.getName())); // 读你刚刚写入的文件
		DbTable dbTable = (DbTable) in.readObject(); // 重新构建你刚刚写入的Object
		System.out.println("dbTable   =   " + dbTable.getTableName());
		System.out.println("columns:"
				+ ArrayUtils.toString(dbTable.getDbColumns()));
	}

}
